var url = window.location.href;

// 从扫哪里传过来的参数；
// var agentshopID = url.split("=")[1];


// var token = new String;
var token_id="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx8d65e23df7356dbb&secret=38137f89a715feddd6291111985c4174";
$.getJSON(token_id,
    function (data) {
       var token = data.access_token;
        fun(token);
});
var sessionID;
function fun(token) {
    var access_token = token;
    var uri = "https://api.weixin.qq.com/cgi-bin/user/info?access_token=";
    //获取用户openid放进去ok了
    var openi = "&openid=oFdhE5xe145mwjzJPSFUBD2LV4rw";
    $.getJSON(uri+access_token+openi,
        function (data) {
            var openid = data.openid;
            $.post("http://www.brandt-beer.com/app/appuser/login",
                {USER_NO:openid},
                function (data) {
                    // console.log(data);
                    var session = data.data;
                    sessionID = session.SESSION_ID;
                    // var url = window.location.href;
                    // var segmentation = url.split("?")[1];
                });
        });
}
function getBeer() {
    //查询店铺：写死
    //买酒领酒
    $.post("http://www.brandt-beer.com/app/agentshop/getShopinfo",
        {AGENTSHOP_ID:2,SESSION_ID:sessionID},function (data) {
            console.log(data);
            var shopType = data.data.SHOP_TYPE;
            // console.log(shopType);
            var agentId = data.data.AGENT_ID;
            // console.log(agentId);
            // 传两个值：1店铺ID；2店铺类型
            window.location.href="./bringWine/cafe/cafeFreeReceiveBeer.html?session="+sessionID+"&SHOP_TYPE="+agentId
        });
}
function buyBeer() {
    // 查询店铺：写死
    // 买酒
    $.post("http://www.brandt-beer.com/app/agentshop/getShopinfo",
        {AGENTSHOP_ID:2,SESSION_ID:sessionID},function (data) {
            console.log(data);
            var  agent_shopID = data.data.AGENTSHOP_ID;
            // console.log(agent_shopID);
            //店铺类型
            var SHOP_TYPE = data.data.SHOP_TYPE;
            console.log(SHOP_TYPE);

            if(SHOP_TYPE==0){
                window.location.href="./buyWine/cafe/goodsList.html?session="+sessionID+"&agentshop_ID="+agent_shopID;
            }else if(SHOP_TYPE==1){
                window.location.href="./buyWine/communityStore/goodsList.html?session="+sessionID+"&agentshop_ID="+agent_shopID;
            }

        });

//         <a href="./buyWine/communityStore/goodsList.html"></a>
//         <a href="./buyWine/cafe/goodsList.html"></a>
}




